/** 纯展示不带请求数据的table */
import React from 'react';
import { Table } from 'antd';
import QueryTable from './table';
import { onSetItemDecorator } from './export';
import shouldComponentUpdate from './decorator/shouldComponentUpdate';

@onSetItemDecorator
@shouldComponentUpdate
class MyTable extends QueryTable {

	componentWillUpdate(nextProps, nextState) {
		this.getPagination(typeof nextProps.current !== 'undefined' && typeof nextProps.total !== 'undefined' ? nextProps : nextState);
	}

	pagesizgeChange = (current, size) => {
		if (this.props.pagesizgeChange) this.props.pagesizgeChange(current, size);
		else this.setState({ size, current: 1 });
	}
	pageChange = current => {
		if (this.props.pageChange) this.props.pageChange(current);
		else this.setState({ current });
	}

	render() {
		const { notShow = [], columns, tableDisplay, noDisplay, ...props } = this.props;
		const { display, dataSource } = this.state;
		return (
			<Table
				columns={this.getColumns((columns).filter(c => !notShow.includes(c.key)), (noDisplay ? null : (tableDisplay || display)))}
				pagination={this.pagination}
				dataSource={dataSource}
				{...props}
			/>
		);
	}
}

export default MyTable;

